home *** CD-ROM | disk | FTP | other *** search
- @echo off
- ! bu.bat Batch file to backup a file or the contents of a folder
- !
- ! bu name [dest]
- !
- ! where 'name' is the item to be copied and 'dest' is the destination
- ! folder. Both parameters can be preceded by paths and volume IDs
- ! If 'dest' is missing, '2:' is assumed. Note that if the source is a folder,
- ! the folder itself is not copied. Therefore, bu fold1 fold2 will
- ! back up the contents of fold1 to fold2 rather than to fold2\fold1.
- !
- ! WARNING: the depth which can backed up is limited by the length of the
- ! command line and the length of your folder names.
- !
- ! To backup a folder to a folder with the same name on a floppy type:
- ! bu folderPath\folderName 2:\folderName
- !
- ! To backup the contents of a folder to the current directory of volume 2 type:
- ! bu folderPath\folderName
- !
- ! bu.bat calls extractName and bu1
- !
- ! Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
- !
-
- ! ensure that the first parameter is there and that the third one is not
- set doserr=13
- if not "%3 " == " " goto DONE_LBL
- if "%1 " == " " goto DONE_LBL
-
- ! save the current directory: we will have to attach back in a couple of places
- set bu_back=%where%
-
- ! determine the destination
- set bu_dest=2:
- if "%2 " == " " goto DEST_OK_LBL
- set doserr=27
- if not existdir "%2" goto DONE_LBL
- !
- ! Determine the full destination path by attaching to the destination
- ! and looking at the global variable WHERE. This will also resolve any
- ! alias in the path. Then attach back to where we were.
- !
- ! You cannot simply set bu_dest to %2, because it might be a relative
- ! path and become useless once you move to subdirectories.
- !
- cd %2
- set bu_dest=%where%
- cd %bu_back%
- :DEST_OK_LBL
-
- onerror DONE_LBL
-
- ! ensure that the item to be backed up is there
- if existdir "%1" goto FOLDER_LBL
- !
- ! it is no directory: it should be a single file
- copy/u "%1" %bu_dest%
- goto DONE_LBL
-
- :FOLDER_LBL
- !
- ! Copy the subdirectory structure without copying any file.
- ! You can achieve this by copying everything while specifying a file type
- ! and/or creator which do not exist.
- !
- xcopy/E/C=mDOS/T=none "%1" "%bu_dest%"
-
- ! recursively copy the files contained in the subdirectories
- set doserr=0
- call bu1 "%1" "%bu_dest%"
-
- ! attach back to the original current directory, which was changed by bu1
- cd "%bu_back%"
-
- :DONE_LBL
- if not %doserr% == 0 show %doserr%
- !
- ! remove the global variables
- set bu_dest=
- set bu_back=
-